package com.tongguan.paypos.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by Joylive on 2016/12/6 .
 */

public class DataBaseOpenHelper extends SQLiteOpenHelper {

    private static final int DB_VERSION = 9;
    private static final String DB_NAME = "signIn.db";

    private static final String sql = "CREATE TABLE IF NOT EXISTS user (_id integer primary key autoincrement, account varchar(80), password varchar(80),merchantName varchar(80), merchantId varchar(80))";

    public DataBaseOpenHelper(Context context) {
        super(context, DB_NAME, null, DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(sql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        if (oldVersion < 9) {
            onCreate(db);
            db.execSQL("INSERT INTO user (account,password) SELECT acount,password FROM member");
            //删除以前的久表
            db.execSQL("DROP TABLE IF EXISTS sign");
            db.execSQL("DROP TABLE IF EXISTS member");
            db.execSQL("DROP TABLE IF EXISTS sync");
        } else {
            db.execSQL("DROP TABLE IF EXISTS user");
            onCreate(db);
        }
    }
}
